{% load i18n %}
<script>
    function on_withdraw(form_id)
    {
        // todo 提示提现金额和得到
        var serial_data = $("#"+form_id).serialize()
        console.log("serial "  + JSON.stringify(serial_data))
        $.post('/btc/withdraw_order',
        serial_data,
        function(data){
            //console.log("data "  + JSON.stringify(data))
            //console.log("data "  + data.result)
            //console.log("data "  + data.msg)
            //console.log("return data  "  + "#"+ form_id +"_msg" )
            //data {"result":false,"msg":"withdraw_amount_to_large"}
            if (data.result == true)
            {
                $("#"+ form_id +"_msg").html("{% trans '提现申请成功'%}");
                msg_tips("<b>{% trans '提现申请成功' %}</b>", 3000);
            }
            else
            {
                var msg = ""
                if (data.msg=="coin_type_error") {
                    msg = "{% trans '请求参数非法'%}"
                }
                if (data.msg=="amount_too_smal") {
                    msg = "{% trans '提现数量小于0'%}"
                }
                if (data.msg=="withdraw_amount_too_smal") {
                    msg = "{% trans '提现数量小于最小提现数量'%}"
                }
                if (data.msg=="withdraw_amount_to_large") {
                    msg = "{% trans '提现数量大于当前可用数量'%}"
                }
                if (data.msg =="address_type_error") {
                    msg = "{% trans '地址格式不正确'%}" 
                }
                console.log("withdraw msg ["+ msg+"]" + "["+ data.msg+"]")
                msg_tips(msg, 3000);
                //$("#msg").html(data.msg);
                $("#"+ form_id +"_msg").html("{% trans '提现申请失败'%}" + ":" +msg);
            }
        });
    }
</script>

<script id="temp_withdraw" type="text/html">
    <% var form_id = "form_withdraw_" + info.coin_type %>
    <form class="form-horizontal" id="<%=form_id%>" method="post" role="form" src>
        {% csrf_token %}
        <div class="col-sm-offset-3 col-sm-6 f-fc">
            <div class="form-group">
                <div class="col-sm-12">
                    <div class="f-left" role="alert" style="font-size:16px">
                        {% trans '可提现金额'%} :<b> <a class="click_amount red"  data-amount="<%=info.amount%>"  style="text-decoration:underline" href="javascript:void(0)" ><%=info.amount%></a></b><br>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-12">
                    <div class="input-group">
                        <span class="input-group-addon ">{% trans '提现地址'%}</span>
                        <input type="text" class="form-control" name="address" id="address">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-12">
                    <div class="input-group">
                        <span class="input-group-addon ">{% trans '提现数量'%}</span>
                        <input type="text" class="form-control" name="amount" id="amount">
                        <span class="input-group-addon"><%=g_coin_info[info.coin_type].name_upper%></span>
                    </div>
                </div>
            </div>
            <!--
            <div class="form-group">
                <div class="col-sm-6">
                    <div class="input-group">
                        <span class="input-group-addon ">{% trans '手续费'%}</span>
                        <input type="text" class="form-control" name="amount" id="amount" >
                        <span class="input-group-addon"><%=g_coin_info[info.coin_type].name_upper%></span>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="input-group">
                        <span class="input-group-addon ">{% trans '到账数量'%}</span>
                        <input type="text" class="form-control" name="amount" id="amount" >
                        <span class="input-group-addon"><%=g_coin_info[info.coin_type].name_upper%></span>
                    </div>
                </div>
            </div>
            -->
            <div class="form-group">
                <div class="col-sm-12">
                    <input type="text" class="form-control" name="coin_type" style="display:none" value="<%=info.coin_type%>">
                    <button type="button" id="withdraw" class="btn btn-block btn-danger" onclick="on_withdraw('<%=form_id%>')">{% trans '提现'%} <%=info.coin_type%></button>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-12">
                    <div class="f-left">
                        <span id="<%=form_id%>_msg" class="red"> </span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-12">
                    <div class="alert alert-warning alert-dismissible f-left" role="alert">
                        {% trans '提现说明:'%}<br>
                        {% trans '最小提现数量'%}:<%=info.min%> <%=info.coin_type%><br>
                        {% trans '平台手续费'%}:<%=info.fee_per%>%<br>
                        {% trans '矿工手续费'%}:<%=info.fee_min%> <%=info.coin_type%><br>
                        {% trans '手续费=提现数量'%} * <%=info.fee%> + <%=info.fee_min%> <%=info.coin_type%>
                    </div>
                </div>
            </div>
        </div>
    </form>
</script>
